﻿using MemberBll;
using MemberModel;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Member_API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MemberController : ControllerBase
    {
        public MemberController(adminBll bll)
        {
            Bll = bll;
        }

        public adminBll Bll { get; }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="zhang">账号</param>
        /// <param name="pwd">密码</param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetAdmin(string zhang, string pwd)
        {
            try
            {
                T_Admin list = Bll.GetAdmin(zhang, pwd);
                return Ok(new
                {
                    data = list
                });
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 显示会员登录列表
        /// </summary>
        /// <param name="name"></param>
        /// <param name="age"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetAdminInfo(string? name, int? age)
        {
            try
            {
                var list = Bll.GetAdminInfo(name, age);
                return Ok(new
                {
                    data = list
                });
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 修改数据
        /// </summary>
        /// <param name="info">实体类</param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult PutAdminInfo(T_Admin info)
        {
            try
            {
                int res = Bll.PutAdminInfo(info);
                return Ok(new
                {
                    data = res
                });
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 反填数据
        /// </summary>
        /// <param name="aid"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Fantian(int aid)
        {
            try
            {
                var res = Bll.Fantian(aid);
                return Ok(new
                {
                    data = res
                });
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
